package com.smh.a03MapDemo3;

import java.util.*;

public class Test2 {
    public static void main(String[] args) {
        
        char[] arr = {'A','B','C','D'};
        Random random = new Random();
        ArrayList<Character> arrayList = new ArrayList<>();
        for (int i = 0; i < 80; i++) {
            arrayList.add(arr[random.nextInt(4)]);
        }

        //统计的东西比较多的话,不方便使用计数器思想
        //我们可以定义map集合,利用map集合进行统计


        Map<Character,Integer> map = new HashMap<>();

        for (int i = 0; i < arrayList.size(); i++) {
            char key = arrayList.get(i);

            if (map.containsKey(key)){
                int value = map.get(key);
                value++;
                map.put(key,value);
            }else {
                map.put(key,1);
            }

        }

        System.out.println(map);

        //求最大值
        int max =0;
        Set<Character> c = map.keySet();
        for (Character key : c) {
            int value = map.get(key);
            if (value>max){
                max=value;
            }
        }

        //找出哪个景点的次数与最大值一样
        for (Character key : c) {
            int value = map.get(key);
            if (value==max){
                System.out.println(key+"="+value);
            }
        }


    }
}
